package com.neuedu.web.dao;

import com.neuedu.web.common.BaseDao;
import com.neuedu.web.po.DeptPO;
import com.neuedu.web.po.UmsUser;
import com.neuedu.web.utils.DBUtils;

import java.lang.reflect.InvocationTargetException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 金山
 * 项目：jdbc-dao
 * site: https://blog.fulfill.com.cn
 * 描述  dept 表的数据访问对象
 * @data  2024年11月21日13:38:03
 */
public class DeptDao extends BaseDao<DeptPO> {



    public List<DeptPO> selectAll(  String sql, Object... params) throws NoSuchFieldException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
        return super.selectAll(DeptPO.class , sql,params);
    }
    public List<DeptPO> selectPage( int current, int size, String sql, Object... params) throws NoSuchFieldException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
        return super.selectPage(DeptPO.class , current ,size,sql,params);
    }



    public DeptPO selectById(long id) throws NoSuchFieldException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {


        String sql = "select * from dept where dept_id= ?";
        return super.selectOne(DeptPO.class,sql,id);

    }



    public int insert(DeptPO dept) {
        String sql = "INSERT INTO `his`.`dept` (   `dept_name`, `loc`, `leader`) VALUES(  ?,?,? )  ";
        int count = super.update(sql,
                dept.getDeptName(),
                dept.getLoc(),
                dept.getLeader()
        );

        return count;

    }


    public int update(DeptPO dept) {
        StringBuffer sql = new StringBuffer();

        sql.append(" update 					");
        sql.append("   `dept` 			");
        sql.append(" set			");
        sql.append("   `dept_name` = ?,			");
        sql.append("   `loc` = ?,			");
        sql.append("   `leader` = ?			");

        sql.append(" where `dept_id` =  ?			");


        int count = super.update(sql.toString(),
                dept.getDeptName(),
                dept.getLoc(),
                dept.getLeader(),
                dept.getDeptId()
        );

        return count;

    }

    /**
     * 通用的方法
     *
     * @return
     */

    public int delete(long id) {
        StringBuffer sql = new StringBuffer();

        sql.append(" delete from dept where dept_id = ?");

        int count = super.update(sql.toString(),   id        );

        return count;

    }


}
